#include <cstdlib>
#include "winAbsThreads.h"

winAbsThreads::winAbsThreads(void)
: _handle(NULL), _startRoutine(NULL), _param(NULL)
{
}

winAbsThreads::winAbsThreads(const ABSSTART ptr, const ABSPARAM param)
: _handle(NULL), _startRoutine(ptr), _param(param)
{
}

winAbsThreads::winAbsThreads(const winAbsThreads &obj)
{
	this->_handle = obj._handle;
	this->_startRoutine=  obj._startRoutine;
	this->_param = obj._param;
}

winAbsThreads&		winAbsThreads::operator=(const winAbsThreads &obj)
{
	if (this != &obj)
	{
		this->_handle = obj._handle;
		this->_startRoutine = obj._startRoutine;
		this->_param = obj._param;
	}
	return (*this);
}

winAbsThreads::~winAbsThreads(void)
{
}

IAbsThreads::~IAbsThreads(void)
{
}

void				winAbsThreads::setStartRoutine(const ABSSTART ptr)
{
	this->_startRoutine = ptr;
}

void				winAbsThreads::setParam(const ABSPARAM param)
{
	this->_param = param;
}

bool				winAbsThreads::createThread(void)
{
	if (this->_startRoutine && this->_param)
	{
		this->_handle = CreateThread(NULL, 0, this->_startRoutine, this->_param, 0, NULL);
		if (this->_handle != NULL)
			return (true);
	}
	return (false);
}

bool				winAbsThreads::waitThread(void)
{
	if (this->_handle)
		if (WaitForSingleObject(this->_handle, INFINITE) != WAIT_FAILED)
			return (true);
	return (false);
}

int					winAbsThreads::terminateThread(void)
{
	return (-1);
}

bool				winAbsThreads::run(void)
{
	if (this->createThread())
		return (this->waitThread());
	return (false);
}